import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/app_colors.dart';
import 'package:xvideos/tools_base/indicator/custom_tab_indicator.dart';
import 'package:xvideos/tools_base/loading/loading_center_widget.dart';
import 'package:xvideos/tools_base/widget/keep_alive_widget.dart';

import 'live_main_logic.dart';
import 'live_sub_page.dart';

//直播首页
class LiveMainPage extends StatefulWidget {
  static bool broadcast = false; //开启直播模块开关
  static bool jumpLiveLink = false; //直播内链跳转初始化

  const LiveMainPage({Key? key}) : super(key: key);

  @override
  State<LiveMainPage> createState() => _LiveMainPageState();
}

class _LiveMainPageState extends State<LiveMainPage> {
  LiveMainLogic logic = Get.put(LiveMainLogic());

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LiveMainLogic>(
      builder: (_) {
        if (logic.liveMainModel == null) return LoadingCenterWidget();
        return Column(
          children: [
            _buildTabbarWidget(),
            Expanded(
              child: TabBarView(
                controller: logic.tabController,
                children: List.generate(
                  logic.liveTabs.length,
                  (index) => keepAliveWrapper(LiveSubPage(tagData: logic.liveTabs[index])),
                ),
              ),
            ),
          ],
        );
      },
    );
  }

  //国家分类
  Widget _buildTabbarWidget() {
    return SizedBox(
      height: 44,
      child: TabBar(
        controller: logic.tabController,
        tabs: List.generate(
          logic.liveTabs.length,
          (index) => Padding(
            padding: const EdgeInsets.only(bottom: 7),
            child: Text(logic.liveTabs[index].title ?? ''),
          ),
        ),
        labelPadding: EdgeInsets.symmetric(horizontal: 9),
        tabAlignment: TabAlignment.start,
        isScrollable: true,
        labelColor: Colors.white.withOpacity(.9),
        labelStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
        unselectedLabelColor: Colors.white.withOpacity(.45),
        unselectedLabelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w400),
        indicator: CustomIndicator(
          height: 4,
          width: 16,
          topLeft: 3,
          topRight: 3,
          color: AppColors.actionRed,
        ),
      ),
    );
  }
}
